package com.example.controller;

import com.example.common.Result;
import com.example.controller.domain.UserRecentSearch;
import com.example.service.SearchService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private SearchService searchService;

    /**
     * 删除redis
     *
     * @param key
     * @return
     */
    @DeleteMapping("/remove")
    public Result removeRedis(String key) {
        redisTemplate.delete(key);
        return Result.success();
    }

    /**
     * 热搜列表
     *
     * @return
     */
    @GetMapping("/listHotSearch")
    public Result listHotSearch() {
        return Result.success(searchService.listHotSearch());
    }

    /**
     * 最近搜索列表
     *
     * @return
     */
    @GetMapping("/listRecentSearch")
    public Result recentHotSearch() {
        return Result.success(searchService.listRecentSearch());
    }

    @DeleteMapping("/removeRecentSearch")
    public Result removeRecentSearch(UserRecentSearch userRecentSearch){
        return Result.success("删除搜索记录成功",searchService.removeRecentSearch(userRecentSearch));
    }

    @DeleteMapping("/removeRecentSearchList")
    public Result removeRecentSearchList(){
        searchService.removeRecentSearchList();
        return Result.success("删除搜索记录成功");
    }
}

